//
//  H_ChangeUserPassWVC.m
//  Honey
//
//  Created by 贾亚涵 on 16/5/8.
//  Copyright © 2016年 贾亚涵. All rights reserved.
//

#import "H_ChangeUserPassWVC.h"

#define OldPassW 3100
#define NewPassW1 3105
#define NewPassW2 3110

@interface H_ChangeUserPassWVC ()<UITextFieldDelegate>
{
    UIImageView * _centerBarIV;
    UILabel * _BarLabel;
    
    UITextField * _oldPassWTF;
    UITextField * _newPassWTF1;
    UITextField * _newPassWTF2;
    UIButton * _changePassWBtn;
    NSString * _RPassWStr1;
    NSString * _RPassWStr2;
    NSString * _RPassWStr3;
}

@end

@implementation H_ChangeUserPassWVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatChangePassWView];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self infoNavigationBarBtn];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [_BarLabel removeFromSuperview];
    
    [_centerBarIV removeFromSuperview];
}

-(void)infoNavigationBarBtn
{
    _centerBarIV = [[UIImageView alloc] initWithFrame:CGRectMake(50, 10, 1, 20)];
    _centerBarIV.backgroundColor = [UIColor blackColor];
    _centerBarIV.alpha = 0.2f;
    [self.navigationController.navigationBar addSubview:_centerBarIV];
    
    _BarLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_centerBarIV.frame)+14, 10, 100, 20)];
    _BarLabel.text = @"更改密码";
    _BarLabel.textColor = [UIColor whiteColor];
    [self.navigationController.navigationBar addSubview:_BarLabel];
}

-(void)creatChangePassWView
{
    _oldPassWTF = [self addRegisterUITFWithPlaceholder:@"请输入原密码" Tag:OldPassW Rect:CGRectMake(20, 104, Screen_Width-40, 40)];
    [self.view addSubview:_oldPassWTF];
    _newPassWTF1 = [self addRegisterUITFWithPlaceholder:@"请输入新密码" Tag:NewPassW1 Rect:CGRectMake(20, 145, Screen_Width-40, 40)];
    [self.view addSubview:_newPassWTF1];
    _newPassWTF2 = [self addRegisterUITFWithPlaceholder:@"确认新密码" Tag:NewPassW2 Rect:CGRectMake(20,186, Screen_Width-40, 40)];
    [self.view addSubview:_newPassWTF2];
    
    _changePassWBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(_newPassWTF2.frame)+30, Screen_Width-40, 30)];
    _changePassWBtn.layer.cornerRadius = 8;
    _changePassWBtn.backgroundColor = [UIColor orangeColor];
    [_changePassWBtn setTitle:@"确认修改" forState:UIControlStateNormal];
    [_changePassWBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_changePassWBtn addTarget:self action:@selector(ChangePassWBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_changePassWBtn];

}

#pragma mark- addUITextFiled
-(UITextField *)addRegisterUITFWithPlaceholder:(NSString *)placeholder Tag:(CGFloat )tag Rect:(CGRect)rect
{
    UITextField * _RLTextFiled = [[UITextField alloc] initWithFrame:rect];
    _RLTextFiled.backgroundColor = [UIColor whiteColor];
    //关闭首字母自动大写
    _RLTextFiled.autocapitalizationType = UITextAutocapitalizationTypeNone;
    _RLTextFiled.borderStyle = UITextBorderStyleRoundedRect;
    //添加清除小标
    _RLTextFiled.clearButtonMode = UITextFieldViewModeWhileEditing;
    //密文
    _RLTextFiled.secureTextEntry = YES;
    _RLTextFiled.placeholder = placeholder;
    [_RLTextFiled addTarget:self action:@selector(RLTFChanged:) forControlEvents:UIControlEventEditingChanged];
    _RLTextFiled.delegate = self;
    _RLTextFiled.tag = tag;
    
    return _RLTextFiled;
}

//对注册信息的限制
-(void)RLTFChanged:(UITextField *)sender
{
    switch (sender.tag)
    {
        case OldPassW:
        {
            NSCharacterSet * CS = [[NSCharacterSet characterSetWithCharactersInString:PassWord_Can_Input] invertedSet];
            NSString * str = [[_oldPassWTF.text componentsSeparatedByCharactersInSet:CS] componentsJoinedByString:@""];
            if (_oldPassWTF.text.length <= 16 && [str isEqualToString:_oldPassWTF.text])
            {
                _RPassWStr1 = _oldPassWTF.text;
                
            }else
            {
                _oldPassWTF.text = _RPassWStr1;
            }

        }
            break;
        case NewPassW1:
        {
            NSCharacterSet * CS = [[NSCharacterSet characterSetWithCharactersInString:PassWord_Can_Input] invertedSet];
            NSString * str = [[_newPassWTF1.text componentsSeparatedByCharactersInSet:CS] componentsJoinedByString:@""];
            if (_newPassWTF1.text.length <= 16 && [str isEqualToString:_newPassWTF1.text])
            {
                _RPassWStr1 = _newPassWTF1.text;
                
            }else
            {
                _newPassWTF1.text = _RPassWStr1;
            }

        }
            break;
        case NewPassW2:
        {
            NSCharacterSet * CS = [[NSCharacterSet characterSetWithCharactersInString:PassWord_Can_Input] invertedSet];
            NSString * str = [[_newPassWTF2.text componentsSeparatedByCharactersInSet:CS] componentsJoinedByString:@""];
            if (_newPassWTF2.text.length <= 16 && [str isEqualToString:_newPassWTF2.text])
            {
                _RPassWStr2 = _newPassWTF2.text;
                
            }else
            {
                _newPassWTF2.text = _RPassWStr2;
            }

        }
            break;
        default:
            break;
    }
}

-(void)ChangePassWBtn:(id)sender
{
    if (sender && [sender isKindOfClass:[UIButton class]])
    {
        //收起键盘
        [self changePackKeyboard];
        //调用提示框第三方
        MBProgressHUD * hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        hud.color = [UIColor orangeColor];
        
        //判断密码是否为空
        if (_oldPassWTF.text.length != 0)
        {
            //判断密码的长度
            if (_oldPassWTF.text.length >= 6 && _oldPassWTF.text.length <= 16)
            {
            }
        }


    }
}

#pragma mark- 收键盘
-(void)changePackKeyboard
{
    [_oldPassWTF resignFirstResponder];
    [_newPassWTF1 resignFirstResponder];
    [_newPassWTF2 resignFirstResponder];
    
}

@end
